//
//  LBMediaPresentViewController.m
//  LangBa
//
//  Created by Mac on 2017/12/21.
//  Copyright © 2017年 stoneobs@icloud.com. All rights reserved.
//

#import "LGCiTangRolationPresentViewController.h"
#import "STPasswordTextField.h"
@interface LGCiTangRolationPresentViewController ()
@property(nonatomic, strong) STButton                     *clearButton;
@property(nonatomic, strong) UIView                     *customView;
@end

@implementation LGCiTangRolationPresentViewController

- (instancetype)init
{
    if (self == [super init]) {
        self.modalPresentationStyle = UIModalPresentationOverFullScreen;
    }
    return self;
}
#pragma mark --vc 生命周期
- (void)viewDidLoad{
    [super viewDidLoad];
    [self configSubView];
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
}
- (void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    [self show];
}
- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
}
- (void)viewDidDisappear:(BOOL)animated{
    [super viewDidDisappear:animated];
}
#pragma mark --subView
- (void)configSubView{
    __weak typeof(self) weakSelf =  self;
    self.clearButton = [[STButton alloc] initWithFrame:UIScreenFrame
                                                 title:nil
                                            titleColor:nil
                                             titleFont:0
                                          cornerRadius:0
                                       backgroundColor:[[UIColor blackColor] colorWithAlphaComponent:0.4]
                                       backgroundImage:nil
                                                 image:nil];
    [weakSelf.clearButton setClicAction:^(UIButton *sender) {
        [weakSelf dismissViewControllerAnimated:NO completion:nil];
    }];
    [self.view addSubview:_clearButton];
    
    self.customView = [[UIView alloc] initWithFrame:CGRectMake(0, UIScreenHeight, UIScreenWidth - 60, 342)];
    self.customView.centerX = UIScreenWidth / 2;
    self.customView.top = UIScreenHeight;
    self.customView.backgroundColor = [UIColor whiteColor];
    self.customView.layer.cornerRadius = 10;
    self.customView.clipsToBounds = YES;
    //    [self.clearButton addSubview:self.customView];
    //    UITapGestureRecognizer * ges = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onSelectedWhiteView)];
    //    self.customView.userInteractionEnabled = YES;
    //    [self.customView addGestureRecognizer:ges];
    
    //sub
    STButton * buyButton = [[STButton alloc] initWithFrame:CGRectMake(0, 0, 311, 311)
                                                     title:nil
                                                titleColor:nil
                                                 titleFont:0
                                              cornerRadius:0
                                           backgroundColor:nil
                                           backgroundImage:nil
                                                     image:[UIImage imageNamed:@"八卦"]];
    buyButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    [buyButton setClicAction:^(UIButton *sender) {

    }];
    buyButton.center = self.view.center;
    [self.clearButton addSubview:buyButton];
    
    
    STButton * closeButton = [[STButton alloc] initWithFrame:CGRectMake(buyButton.right - 30, buyButton.top, 20, 20)
                                                       title:nil
                                                  titleColor:nil
                                                   titleFont:0
                                                cornerRadius:0
                                             backgroundColor:nil
                                             backgroundImage:[UIImage imageNamed:@"关闭"]
                                                       image:nil];
    closeButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    [closeButton setClicAction:^(UIButton *sender) {
        [weakSelf dismissViewControllerAnimated:NO completion:^{
            
        }];
    }];
    
    [self.clearButton addSubview:closeButton];
}
#pragma mark --Private Method
- (void)show{
    [UIView animateWithDuration:0.6
                          delay:0
         usingSpringWithDamping:0.6
          initialSpringVelocity:0.7
                        options:UIViewAnimationOptionLayoutSubviews
                     animations:^{
                         // self.customView.centerY = UIScreenHeight / 2;
                     } completion:^(BOOL finished) {
                         
                     }];
}
- (void)dismiss{
    [self.view endEditing:YES];
    [UIView animateWithDuration:0.25 animations:^{
        self.customView.top = UIScreenHeight;
        self.clearButton.alpha = 0;
    } completion:^(BOOL finished) {
        [self dismissViewControllerAnimated:NO completion:nil];
    }];
}
- (void)dismissWithHandle:(void(^)())handle{
    [self.view endEditing:YES];
    [UIView animateWithDuration:0.25 animations:^{
        self.customView.top = UIScreenHeight;
        self.clearButton.alpha = 0;
    } completion:^(BOOL finished) {
        [self dismissViewControllerAnimated:NO completion:^{
            if (handle) {
                handle();
            }
        }];
    }];
}
#pragma mark --Action Method

- (void)onSelectedCancleButton{
    
    [self dismiss];
    
}
- (void)onSelectedWhiteView{
    [self.view endEditing:YES];
}

@end




